<?php

namespace App\Models;

use Carbon\Carbon;
use App\Models\Traits\GoldCoinsTrait;
use App\Models\Traits\HasScopeInquire;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use DateTimeInterface;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class GroupCard extends Model
{
    use HasFactory, HasScopeInquire;

    protected $guarded = ['id'];

	protected $casts = [
		'data' => 'json'
	];

	public function scopeCanUsed(Builder $builder)
    {
        return $builder->where('is_used', false)->where('card_expired_at','>',Carbon::now());
    }

    public function user(): BelongsTo
    {
    	return $this->belongsTo(User::class);
    }
}
